package leetcode_周赛._2021._202106._20210613;

import java.util.Arrays;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/6/13 10:40
 * 可移除字符的最大数目
 * 算法：字符串
 * 判断 s 中的哪些字符去掉后，p 还是 s 的子序列
 *
 */
public class _5786 {
    public static void main(String[] args) {
        System.out.println(new _5786().isSon("abc", "ab"));
        System.out.println(new _5786().isSon("bacc", "ab"));
        String s = "a23";
        char[] array = s.toCharArray();
        array[0] = '1';
        System.out.println(Arrays.toString(array));
    }

    public int maximumRemovals(String s, String p, int[] removable) {
        char[] array = s.toCharArray();
        int i = 1;
        for (; i <= removable.length; i++) {
            char c = array[removable[i - 1]];
            array[removable[i -1]] = ' ';
            if (p.contains(c + "")) {
                StringBuilder tmp = new StringBuilder();
                for (char c1 : array) tmp.append(c1);
                if (!isSon(tmp.toString(), p)) return i - 1;
            }
        }
        return i - 1;
    }
    private boolean isSon(String s, String p) {
        if (p.length() == 0) return true;
        int f = 0;
        for (char c : s.toCharArray()) {
            if (f == p.length()) return true;
            if (c == p.charAt(f)) ++f;
        }
        return f == p.length();
    }

}
